//
//  SDApplyCell.m
//  SuperDoctor
//
//  Created by fdq on 16/7/6.
//  Copyright © 2016年 SD. All rights reserved.
//

#import "SDApplyCell.h"

@interface SDApplyCell()


@end

@implementation SDApplyCell


//重写initWithStyle,添加控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
	
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	
	if (self) {
		
		//设置病人姓名
		UILabel * patientLabel = [[UILabel alloc]init];
		
		self.patientNameLabel =patientLabel;
		
		[self.contentView addSubview:patientLabel];
		
		patientLabel.font = [UIFont systemFontOfSize:15];
		
		[patientLabel mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_offset(10);
			make.height.mas_equalTo(30);
			make.top.mas_offset(10);
			
		}];
		
		//右侧圆形图片位置
		UILabel * imgLabel = [[UILabel alloc]init];
		
		imgLabel.numberOfLines = 0;
		
		imgLabel.textAlignment = NSTextAlignmentCenter;
		
		self.checkStateLabel = imgLabel;
		
		imgLabel.font = [UIFont systemFontOfSize:14];
		
		imgLabel.backgroundColor = kThemeColor;
		
		[self.contentView addSubview:imgLabel];
		
		[imgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.right.mas_offset(0);
			
			make.width.mas_equalTo(60);
			
			make.centerY.mas_equalTo(self.contentView.mas_centerY);
			
			make.height.mas_equalTo(60);
			
		}];
		imgLabel.layer.cornerRadius = 30;
		
		imgLabel.layer.masksToBounds = YES;
		

		//添加病情label
		UILabel * diseaseLabel = [[UILabel alloc]init];
		
		self.diseaseTypeLabel = diseaseLabel;
		
		[self.contentView addSubview:diseaseLabel];
		
		diseaseLabel.textAlignment = NSTextAlignmentLeft;

		
		diseaseLabel.textColor = [UIColor grayColor];

		diseaseLabel.font = [UIFont systemFontOfSize:15];
				
		[diseaseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_equalTo(patientLabel.mas_right).offset(10);
			
			make.top.mas_offset(10);
			
			make.height.mas_equalTo(30);

		}];
		
		//就诊时间
		UILabel * timeLabel = [[UILabel alloc]init];
		
		self.timeLabel = timeLabel;
		
		timeLabel.font = [UIFont systemFontOfSize:14];
		
		timeLabel.textColor = [UIColor grayColor];

		[self.contentView addSubview:timeLabel];
		
		[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		
			make.left.mas_equalTo(diseaseLabel.mas_right).offset(10);
			
			make.top.mas_offset(10);
			
			make.right.mas_equalTo(imgLabel.mas_left).offset(-5);
			
			make.height.mas_offset(30);
		}];
		
		//添加医生姓名
		UILabel * doctorLabel = [[UILabel alloc]init];
		
		self.doctorNameLabel = doctorLabel;
		
		[self.contentView addSubview:doctorLabel];
		
		doctorLabel.font = [UIFont systemFontOfSize:14];
		
		[doctorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_offset(10);
			
			make.bottom.mas_offset(-10);
			
			make.height.mas_offset(30);
		}];
		
		//添加医生职位
		UILabel * positionLabel = [[UILabel alloc]init];
		
		self.doctorTypeLabel = positionLabel;
		
		[self.contentView addSubview:positionLabel];
		
		positionLabel.font = [UIFont systemFontOfSize:14];
		
		positionLabel.textColor = [UIColor grayColor];

		[positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		
			make.left.equalTo(doctorLabel.mas_right).offset(10);
			
			make.bottom.mas_offset(-10);
			
			make.height.mas_offset(30);
		}];
		
		//医院名称
		UILabel * hospitalLabel = [[UILabel alloc]init];
		
		self.hospitalNameLabel = hospitalLabel;
		
		[self.contentView addSubview:hospitalLabel];
		
		hospitalLabel.font = [UIFont systemFontOfSize:14];
		
		hospitalLabel.textColor = [UIColor grayColor];
		
		hospitalLabel.textAlignment = NSTextAlignmentRight;

		[hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.left.mas_equalTo(positionLabel.mas_right).offset(10);
			
			make.bottom.mas_offset(-10);
			
			make.height.mas_equalTo(30);
			
			make.right.mas_equalTo(imgLabel.mas_left).mas_offset(-5);

		}];
		
		//设置中间分割线
		UIView * lineView = [[UIView alloc]init];
		
		self.lineView = lineView;
		
		[self.contentView addSubview:lineView];
		
		
		[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
			
			make.right.mas_equalTo(imgLabel.mas_left);
			
			make.height.mas_equalTo(1);
			
			make.top.mas_offset(49);
			
			make.left.mas_offset(10);
			
			
		}];
		
		
	}
	
	
	return self;
}

//重写model的set方法
- (void)setModel:(SDApplyModel *)model{
	
	_model = model;
	
	//给lable的文字赋值
	self.doctorTypeLabel.text = model.doctorType;
	
	self.doctorNameLabel.text = model.doctorName;
	
	self.patientNameLabel.text = model.patientName;
	
	self.diseaseTypeLabel.text = model.diseaseType;
	
	self.timeLabel.text = model.time;
	
	self.hospitalNameLabel.text = model.hospitalName;
	
	self.checkStateLabel.text = model.checkState;
	
	self.lineView.backgroundColor = [UIColor blueColor];
	
	//进行判断,如果审核失败,则显示红色,已就诊显示灰色
	if ([self.checkStateLabel.text isEqualToString:@"审核失败"]) {
		
		self.lineView.backgroundColor = [UIColor redColor];

		self.checkStateLabel.backgroundColor = [UIColor redColor];
		
	}else if([self.checkStateLabel.text isEqualToString:@"已就诊"]){
		
		self.lineView.backgroundColor = [UIColor grayColor];
		
		self.checkStateLabel.backgroundColor = [UIColor grayColor];
		
	}
	
}




@end
